import 'dart:typed_data';

import 'package:inmotion_protocol/common/product_version.dart';
import 'package:inmotion_protocol/common/vehicle_info.dart';
import 'package:inmotion_protocol/lorin/factory/special/euc/euc_message_factory.dart';
import 'package:inmotion_protocol/lorin/lorin_message.dart';
import 'package:inmotion_protocol/util/byte_util.dart';

class V6MessageFactory extends EucLorinSpecialMessageFactory<_V6Cmd> {
  V6MessageFactory(ProductProperty productProperty) : super(productProperty);

  @override
  LorinMessage genHeadlightOnOffMsg(
      {bool? on, bool? lowBeamOn, bool? highBeamOn, int? source, int? target}) {
    return genSpecialOne2OneWriteMsg(
        compact!.headlightOnOffCmd(),
        Uint8ClampedList.fromList([
          ByteUtil.bool2Byte(on ?? true).value,
          ByteUtil.bool2Byte(false).value
        ]));
  }

  @override
  LorinMessage genSetLightEffectModeMsg(int mode,
      [Uint8ClampedList? param, int? source, int? target]) {
    if (param == null) {
      throw Exception(
          "Param [param] for 'genSetLightEffectModeMsg' must be set in V6.");
    }
    return genSpecialOne2OneWriteMsg(compact!.lightEffectModeCmd(),
        ByteUtil.buildBytes(ByteUtil.num2BytesLe(mode, 1), param));
  }

  LorinMessage genRequestLightEffectMsg() {
    return genSpecialOne2OneReadMsg(compact!.lightEffectModeCmd());
  }

  @override
  void initCompact(int apiVersion, VersionWrapper version) {
    compact = _V6CmdDefault();
  }
}

abstract class _V6Cmd extends EucCmdCompact {
  // 转向灯
  int turnLight() => 42;

  @override
  int autoHeadlightBrightnessThrCmd() => 42;

  @override
  int brightnessOfHeadlightCmd() => 43;

  // 提手按键功能开关
  int handleButtonState();

  // 远近光自动切换速度阈值开关
  int speedThrOfLowHighBeamSwitchCmd();

  // 显示屏自动熄屏
  int autoScreenOffCmd();

  int warningLimitSpeedCmd();

  // 加减速反馈调节
  int speedingFeedback();

  @override
  int soundWaveCmd() {
    return super.soundPackCmd();
  }

  @override
  int assistBalanceCmd() => 65;

  @override
  int bermAngleModeCmd() => 0;
}

class _V6CmdDefault extends _V6Cmd {
  @override
  int autoHeadlightCmd() => 47;

  @override
  int speedThrOfLowHighBeamSwitchCmd() {
    return 48;
  }

  @override
  int brightnessOfHeadlightCmd() => 43;

  @override
  int deviceNameCmd() => 12;

  @override
  int headlightOnOffCmd() => 80;

  @override
  int lightEffectIdCmd() => 45;

  @override
  int lightEffectModeCmd() => 51;

  @override
  int passwordCmd() => 10;

  @override
  int passwordTypeCmd() => 11;

  @override
  int remainderRangeEstimateCmd() => 63;

  @override
  int soundWaveCmd() => 57;

  @override
  int soundWaveSensitivityCmd() => 56;

  @override
  int usbPowerCmd() => 60;

  @override
  int playSoundItemCmd() => 81;

  @override
  int handleButtonState() => 46;

  @override
  int autoScreenOffCmd() => 61;

  @override
  int warningLimitSpeedCmd() => 62;

  @override
  int speedingFeedback() => 64;
}
